package cn.kgm.makeGodV2.event;

import cn.kgm.makeGodV2.GamePlayer;
import cn.kgm.makeGodV2.WorldState;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2025-9-16 10:37
 * @Description: cn.kgm.makeGodV2.event.EventManager
 */
@Data
public class EventManager {
    private List<GameEvent> events;
    private WorldState worldState;

    public EventManager(WorldState worldState) {
        this.worldState = worldState;
        this.events = new ArrayList<>();
    }

    public void addEvent(GameEvent event) {
        events.add(event);
    }

    public void processNPC(GamePlayer npc) {
        for (GameEvent event : events) {
            if (event.checkTriggers(npc, worldState)) {
                EventChoice choice = event.selectChoice(npc);
                if (choice != null) {
                    choice.applyOutcomes(npc, worldState);
                    System.out.println(npc.getName() + " experienced event: " + event.getName() +
                            " and chose: " + choice.getText());
                    break; // 一次只处理一个事件
                }
            }
        }
    }
}
